package org.gwu.seuss.communication.util;

import java.io.File;
import java.io.IOException;

public class FileUtils {

	private static final String SEUSS_DIR = "seuss";
	
	/**
	 * 
	 * @param filename
	 * @param fileArray
	 * @throws Exception
	 */
	public static void writeFile(String filename, byte[] fileArray) throws Exception {
		org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(SEUSS_DIR, filename), fileArray);
	}

	/**
	 * 
	 * @param filename
	 * @param fileArray
	 * @throws Exception
	 */
	public static void writeFile(String filename, String directory, byte[] fileArray) throws Exception {
		org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(directory, filename), fileArray);
	}
	/**
	 * 
	 * @param filename
	 * @param location
	 * @return
	 * @throws Exception
	 */
	public static byte[] readFile(String filename) throws Exception {
		File file = new File(SEUSS_DIR, filename);
		return org.apache.commons.io.FileUtils.readFileToByteArray(file);
	}
	
	public static void deleteFile(String filename) throws IOException {
		File file = new File(SEUSS_DIR, filename);
		org.apache.commons.io.FileUtils.forceDelete(file);
	}
}